package com.niit.project.controller;

import com.niit.project.entity.Report;
import com.niit.project.service.ReportService;
import com.niit.project.service.impl.ReportServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;


@WebServlet(name = "AdminReportController", value = "/AdminReportController")
public class AdminReportController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           //接收数据
            String report = request.getParameter("report");
            ReportService reportService = new ReportServiceImpl();
            //调用addReport方法
            reportService.addReport(report);
            System.out.println("发布成功！");
            //将展示所有公告的结果存储在一个list类型的集合里
            List<Report> allReport = reportService.showAllReport();
            //向请求中存储对象
            request.setAttribute("report",allReport);
            //重定向
            response.sendRedirect(request.getContextPath()+"/GoodsList.jsp");

    }
}
